/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package validar;

import javax.faces.component.*;
import javax.faces.context.*;
import java.util.regex.*;
import javax.faces.application.FacesMessage;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author ruanda
 */
public class validarletras2 implements Validator {


    public validarletras2() {
    }


    @Override
    public void validate(FacesContext facesContext, UIComponent uIComponent, Object object) throws ValidatorException {
        String enteredletra = (String) object;
            Pattern p = Pattern.compile("^[a-zA-Záéíóúñ,]+(\\s|[a-z,]|[A-Za-záéíóúñ,])*");
        Matcher m = p.matcher(enteredletra);
        boolean matchFound = m.matches();

        if (matchFound==false && enteredletra.isEmpty()==false) {
            FacesMessage message = new FacesMessage();
            message.setSummary("Ingrese (Unicamente letras).");
            throw new ValidatorException(message);
        }
    }
}

